package com.baichang.taoshunda.service.impl;

import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.dao.BackgroundImageDao;
import com.baichang.taoshunda.entity.BackgroundImage;
import com.baichang.taoshunda.service.BackgroundImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by ${wushenglu} on 2018/3/12.
 */
@Service
public class BackgroundImageServiceImpl implements BackgroundImageService {
    @Autowired
    private BackgroundImageDao backgroundImageDao;

    @Override
    public boolean addBackGroundImage(Integer userId, String backGroundImage) {
        BackgroundImage backgroundImage = new BackgroundImage();
        backgroundImage.setUserId(userId);
        backgroundImage.setImage(backGroundImage);
        return backgroundImageDao.save(backgroundImage) > 0;
    }

    /**
     * 查询背景素材库
     *
     * @param userId
     * @param nowPage
     * @param pageSize
     * @return
     */
    @Override
    public List<Map<String, Object>> findBackGroundImageList(Integer userId, Integer nowPage, Integer pageSize) {
        return backgroundImageDao.findBackGroundImageList(userId, nowPage, pageSize);
    }

    /**
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> queryImage() {
        return backgroundImageDao.queryImage();
    }

    /**
     *
     * @param picture
     * @return
     */
    @Override
    public long addImage(String picture) throws ServiceException {
        BackgroundImage backgroundImage = new BackgroundImage();
        if(picture.equals("")){
            throw new ServiceException("请添加图片");
        }
        backgroundImage.setImage(picture);
        backgroundImage.setUserId(0);
        return backgroundImageDao.save(backgroundImage);
    }

    /**
     *
     * @param id
     * @return
     */
    @Override
    public int deletePic(Integer id) {
        return backgroundImageDao.deleteById(id);
    }
}
